home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / iconise < prev    next >
Encoding:
Text File  |  1989-02-03  |  11.8 KB  |  359 lines

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: hjt%UUCP.warwick@CUNYVM.CUNY.EDU (Harv (Max) Thompson)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i079: Iconise -- convert SunView icons to text
  5. Keywords: icons, SunView, Suntools, garfield
  6. Message-ID: <869@ubu.warwick.UUCP>
  7. Date: 10 Dec 88 02:18:48 GMT
  8. Sender: allbery@ncoast.UUCP
  9. Reply-To: hjt%UUCP.warwick@CUNYVM.CUNY.EDU (Harv (Max) Thompson)
  10. Organization: Computer Science, Warwick University, UK
  11. Lines: 345
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. Posting-number: Volume 5, Issue 79
  15. Submitted-by: "Harv (Max" <hjt%UUCP.warwick@CUNYVM.CUNY.EDU>
  16. Archive-name: iconise
  17.  
  18. [That From: line looks a bit weird:  beware when replying!  ++bsa]
  19.  
  20. For all those lucky enough to have access to SunView / Suntools on
  21. any type of Sun graphical workstation here is a shar containing a neat
  22. program to build a text version of all your favourite icons...
  23.  
  24. In fact this program should work on any machine - all you need is at least
  25. 64 * 18 character display, a standard C compiler, and access
  26. (downloads) of the afore mentioned icon files.
  27.  
  28. Im not to sure if any other icon formats exist - mail me if you have any
  29. fixes / bugs or ideas.
  30.  
  31.         Have fun
  32.             Harv J "Max" Thompson
  33.  
  34. #! /bin/sh
  35. # This is a shell archive, meaning:
  36. # 1. Remove everything above the #! /bin/sh line.
  37. # 2. Save the resulting text in a file.
  38. # 3. Execute the file with /bin/sh (not csh) to create the files:
  39. #    README.iconise
  40. #    garfield.icon2
  41. #    iconise.1
  42. #    iconise.c
  43. # This archive created: Fri Dec  9 13:01:43 1988
  44. # By:    Harvey J Thompson ()
  45. export PATH; PATH=/bin:$PATH
  46. if test -f 'README.iconise'
  47. then
  48.     echo shar: will not over-write existing file "'README.iconise'"
  49. else
  50. cat << \SHAR_EOF > 'README.iconise'
  51. SHIPPING:                       Contents
  52.     README.iconise          This file
  53.     iconise.c               Source file
  54.     garfield.icon2          Test icon
  55.         iconise.1               Nroff source for man entry
  56.  
  57. See iconise.c and iconise.1 (nroff type manual entry) for description
  58. of the program. To compile it use:
  59.  
  60. cc -O -o iconise iconise.c
  61.  
  62. as a test try:
  63.  
  64.     iconise -w 2 -h 1 garfield.icon2 | (some printer with 132 * 66 page)
  65.  
  66. or on any 64*18 or larger screen...
  67.  
  68.     iconise garfield.icon2
  69.  
  70. It is a very simple program I wrote since we at Warwick University
  71. have periodic access to Sun Graphics workstations and miss our LOVELY icons...
  72.  
  73. The garfield icon was by me also - just shows that at least a few computer
  74. nerds actually can do other things than write silly programs.
  75.  
  76. ______________________________________________________________________________
  77.  
  78. Snail Mail:                  ________________   Aliases:
  79. Harv J Thompson              \ \__________  /   Well they call me "Max"
  80. Dept. Of Computer Science     \ \______  / /
  81. University Of Warwick          \  __  / / /     Quote:
  82. Coventry CV4 7AL                \ \ \/ / /  "I smell like a good cup of coffee"
  83. ENGLAND                          \ \  / /   - said by me at around 5am after
  84.                                   \ \/ /    a particularly long nights hacking
  85. E-mail:                            \/ /     session!
  86. hjt@opal.warwick.ac.uk (1988-)      \/
  87. ______________________________________________________________________________
  88. SHAR_EOF
  89. fi # end of overwriting check
  90. if test -f 'garfield.icon2'
  91. then
  92.     echo shar: will not over-write existing file "'garfield.icon2'"
  93. else
  94. cat << \SHAR_EOF > 'garfield.icon2'
  95. /* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
  96.  */
  97.     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8000,0x0000,0x0000,0x0003,
  98.     0x8000,0x0000,0x0000,0x0003,0x8000,0x0F80,0x3E00,0x0003,
  99.     0x8000,0x1FE0,0xFF00,0x0003,0x8000,0x1FD1,0x3F00,0x0003,
  100.     0x8000,0x1FCE,0x7F00,0x0003,0x8000,0x2AA0,0xAA80,0x0003,
  101.     0x8000,0x2AA0,0xAA80,0x0003,0x80F8,0x3551,0x5480,0x0003,
  102.     0x8006,0x2491,0x2283,0x8003,0x8002,0x6A4A,0x94DC,0x6003,
  103.     0x8071,0x4004,0x0060,0x0003,0x818D,0x8004,0x007E,0x0003,
  104.     0x8007,0x0000,0x0033,0x0003,0x800E,0x0000,0x003C,0x8003,
  105.     0x801E,0x00F1,0xE03E,0x0003,0x803C,0x030A,0x183F,0x0003,
  106.     0x807C,0x0404,0x043F,0x0003,0x807C,0x0804,0x023C,0x8003,
  107.     0x80FE,0x0804,0x0230,0x8003,0x80FE,0x0804,0x0200,0x4003,
  108.     0x809F,0x0804,0x0200,0x6003,0x8100,0x0804,0x0200,0xE003,
  109.     0x8100,0x0804,0x0200,0xF003,0x8380,0x0804,0x0200,0xF803,
  110.     0x8380,0x0835,0x8201,0xF803,0x83C0,0xF835,0x83E1,0xC403,
  111.     0x83E1,0x0835,0x8210,0x0403,0x83F2,0x0804,0x0208,0x0403,
  112.     0x83E2,0x2404,0x0488,0x0403,0x8380,0x420E,0x0848,0x0C03,
  113.     0x8300,0xF1FF,0xF1E0,0x3C03,0x8300,0x480E,0x0240,0x7C03,
  114.     0x8200,0x4C35,0x8640,0xFC03,0x8200,0x4BE4,0xFA40,0x7803,
  115.     0x8200,0x3924,0x9380,0x3803,0x8200,0x2D24,0x9680,0x1003,
  116.     0x8300,0x2BFF,0xFA80,0x1003,0x81C0,0x2924,0x9280,0x1003,
  117.     0x81F0,0x2924,0x9280,0x3003,0x81F0,0x1924,0x9308,0x6003,
  118.     0x81F0,0x0924,0x920F,0xC003,0x80E0,0x07FF,0xFC0F,0xC003,
  119.     0x80C0,0x0000,0x000F,0x8003,0x80C0,0x6000,0x030F,0x0003,
  120.     0x8021,0xE000,0x070E,0x0003,0x803F,0xE000,0x07CC,0x0003,
  121.     0x8007,0xE000,0x07F0,0x0003,0x8000,0xF0C0,0xCF00,0x0183,
  122.     0x8000,0x1F00,0x3C00,0x0183,0x8000,0x0000,0x0000,0x0383,
  123.     0x8000,0x0000,0x0000,0x0303,0x83C2,0x1E7B,0xBD07,0x8303,
  124.     0x8405,0x1141,0x2104,0x4703,0x8805,0x1141,0x2104,0x4603,
  125.     0x89C8,0x9E71,0x3904,0x4003,0x884F,0x9141,0x2104,0x4003,
  126.     0x8850,0x5141,0x2104,0x4C03,0x8790,0x5143,0xBDF7,0x8C03,
  127.     0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
  128.     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF
  129. SHAR_EOF
  130. chmod +x 'garfield.icon2'
  131. fi # end of overwriting check
  132. if test -f 'iconise.1'
  133. then
  134.     echo shar: will not over-write existing file "'iconise.1'"
  135. else
  136. cat << \SHAR_EOF > 'iconise.1'
  137. .TH ICONISE 1 "23rd November 1988"
  138. .\"@(#)iconise.1 1.1 87/04/29 SMI;
  139. .SH NAME
  140. iconise \- produces ASCII image of an icon produced on SunView
  141. .SH SYNOPSIS
  142. iconise [-h ratio] [-w ratio] file
  143. .SH DESCRIPTION
  144. .LP
  145. This program takes a standard icon image file produced under SunView, or
  146. Suntools on standard Sun workstations. The result is printed on
  147. standard-out, and so the program maybe used as a pipe. The options
  148. have the following effect;
  149. .RS
  150. .nf
  151. .TP 20
  152. -h ratio
  153. Allows height compression of either 1, 2 or 4
  154. pixels. The default is 4 pixels. (NB. Density
  155. mapping is performed.)
  156. .TP
  157. -w ratio
  158. Allows width expansion of either 1, 2 or 4 pixels.
  159. The default is 1 pixel.
  160. .fi
  161. .RE
  162. .LP
  163. The best result for printouts would be obtained by;
  164. .IP
  165. iconise -h 1 -w 2 <icon-file> | lpr
  166. .SH BUGS
  167. .LP
  168. None found as yet
  169. .SH AUTHOR
  170. .LP
  171. Harvey J "Max" Thompson (hjt@cs.warwick.ac.uk)
  172. .LP
  173. (C) 1988 Helios Software Ltd. All rights reserved.
  174. SHAR_EOF
  175. chmod +x 'iconise.1'
  176. fi # end of overwriting check
  177. if test -f 'iconise.c'
  178. then
  179.     echo shar: will not over-write existing file "'iconise.c'"
  180. else
  181. cat << \SHAR_EOF > 'iconise.c'
  182. /****************************************************************************\
  183.  * iconise - program to display SunView icon images on terminals
  184.  * (C) 1988 Helios Software Ltd. All rights reserved. Harvey J "Max" Thompson
  185.  * #include <public.domain.h>....
  186.  * This software and its associated source files are now in the PUBLIC DOMAIN
  187.  * - no inclusion in any packages whatsoever for monetry gain is
  188.  * allowed without the written consent of the author. The source files
  189.  * must ( 8- ) be freely distrubited, and any changes must be made in the
  190.  * spirit of PD software - Ie. Dont change any copyrights and authuorships.
  191.  * BUGS+IDEAS+CHANGES: mail me direct at:-
  192.  * JANET: hjt@cs.warwick.ac.uk
  193.  * UUCP: hjt@warwick.UUCP
  194.  * ARPA: hjt%warwick@cs.ucl.ac.uk
  195.  * You should be able to work it out from there.....
  196. \****************************************************************************/
  197.  
  198. #include <sys/types.h>
  199. #include <stdio.h>
  200. #define MAX_X 64
  201. #define MAX_Y 64
  202. #define res_string(xxx,lll) if ((xxx = (char *) malloc (lll)) == NULL)\
  203. $fprintf(stderr,"%s: Ran out of memory\n",argv[0]);exit(1);
  204. #define help (void) fprintf(stderr, "Usage: iconise [-h ratio] [-w ratio]
  205.  file\n")
  206.  
  207. main(argc, argv)
  208. char **argv;
  209. int argc;
  210. $
  211.   FILE *icon;
  212.   char *density = " `\'\"-^=o.:|!;O@#", *file = NULL;
  213.  
  214.   /* you could change density to a better gradient - but this does the */
  215.   /* trick okish */
  216.  
  217.   int fv = 0, wd = 0, ht = 0, dp = 0, vbpi = 0;
  218.   int hratio = 4;
  219.   int wratio = 1;
  220.   int image[MAX_Y][MAX_X], x, y, line, i, j, k;
  221.  
  222.   switch (argc) $
  223.  case 2:
  224.     file = argv[1];
  225.     break;
  226.  case 6:
  227.     file = argv[5];
  228.     if (strcmp (argv[3], "-h") == 0) $
  229.       hratio = atoi(argv[4]);
  230.       if ((hratio != 1) && (hratio != 2) && (hratio != 4)) $
  231.     help;
  232.     exit(1);
  233.       
  234.     
  235.     if (strcmp (argv[3], "-w") == 0) $
  236.       wratio = atoi (argv[4]);
  237.       if ((wratio != 1) && (wratio !=2) && (hratio != 4)) $
  238.     help;
  239.     exit(1);
  240.       
  241.     
  242.  case 4:
  243.     if (file == NULL)
  244.       file = argv[3];
  245.     if (strcmp (argv[1], "-h") == 0) $
  246.       hratio = atoi(argv[2]);
  247.       if ((hratio != 1) && (hratio != 2) && (hratio != 4)) $
  248.     help;
  249.     exit(1);
  250.       
  251.     
  252.     if (strcmp (argv[1], "-w") == 0) $
  253.       wratio = atoi (argv[2]);
  254.       if ((wratio != 1) && (wratio !=2) && (hratio != 4)) $
  255.     help;
  256.     exit(1);
  257.       
  258.     
  259.     break;
  260.  default:
  261.     help;
  262.     exit(1);
  263.   
  264.  
  265.   if ((icon = (FILE *) fopen (file, "r")) == NULL) $
  266.     (void) fprintf (stderr, "%s: file %s not found\n", argv[0], argv[1]);
  267.     exit(1);
  268.   
  269.   (void) fscanf (icon, "\n");
  270.   (void) fscanf (icon, "/* Format_version=%d", &fv);
  271.   (void) fscanf (icon, ", Width=%d", &wd);
  272.   (void) fscanf (icon, ", Height=%d", &ht);
  273.   (void) fscanf (icon, ", Depth=%d", &dp);
  274.   (void) fscanf (icon, ", Valid_bits_per_item=%d\n  */", &vbpi);
  275.  
  276.   if (fv != 1) $
  277.     (void) fprintf (stderr, "%s: Unknown icon format\n", argv[0]);
  278.     exit(1);
  279.   
  280.  
  281.   if (dp != 1) $
  282.     (void) fprintf (stderr, "%s: Cannot iconise depth of %d\n", argv[0], dp);
  283.     exit(1);
  284.   
  285.  
  286.   if (wd > MAX_X) $
  287.     (void) fprintf (stderr, "%s: Icon image to wide\n", argv[0]);
  288.     exit(1);
  289.   
  290.  
  291.   if (ht > MAX_Y) $
  292.     (void) fprintf (stderr, "%s: Icon image to high\n", argv[0]);
  293.     exit(1);
  294.   
  295.  
  296.   /* read in the array from the iconfile */
  297.   /* and convert the hex format into a bit image in the array image */
  298.  
  299.   for (y = 0; y < ht; y += 2) $
  300.     (void) fscanf (icon, "\t");
  301.     for (i = 0; i < 2; i++) $
  302.       for (j = 0; j < 4; j++) $
  303.     (void) fscanf (icon, "%i,", &line);
  304.     for (k = 0; k < 16; k++) $
  305.       image[y+i][j*16+k] = (line & 0x8000) >> 15;
  306.       line = (line << 1);
  307.     
  308.       
  309.     
  310.   
  311.  
  312.   /* hratio  j (possible density numbers)                Really like j as
  313.    *      1       0 1                                        0 15
  314.    *      2       0 1 2 3                                  0 5 10 15
  315.    *      4       0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    (as it is)
  316.    */
  317.  
  318.   for (y = 0; y < ht; y+=hratio) $
  319.     for (x = 0; x < wd; x++) $
  320.       /* add up the density for the current output square */
  321.       for (j = 0, i = 0; i < hratio; i++) $
  322.     j += (image[y+i][x] << i);
  323.       
  324.       /* make j the correct range */
  325.       switch (hratio) $
  326.     case 1:
  327.     j = j * 15;
  328.     break;
  329.     case 2:
  330.     j = j * 5;
  331.     break;
  332.     default:
  333.     break;
  334.       
  335.       /* print the density a number of times depending on width ratios */
  336.       for (k = 0; k < wratio; k++)
  337.     (void) printf ("%c",density[j]);
  338.     
  339.     (void) printf ("\n");
  340.   
  341.  
  342. SHAR_EOF
  343. fi # end of overwriting check
  344. #    End of shell archive
  345. exit 0
  346.  
  347. ______________________________________________________________________________
  348.  
  349. Snail Mail:                  ________________   Aliases:
  350. Harv J Thompson              \ \__________  /   Max
  351. Dept. Of Computer Science     \ \______  / /
  352. University Of Warwick          \  __  / / /     Quote:
  353. Coventry CV4 7AL                \ \ \/ / /  Dreamers dream of dreams becoming
  354.                                  \ \  / /   reality. Realists realise that
  355. EMail:                            \ \/ /    realism is a dream. But only I
  356.                                    \/ /     realise that dreams may become
  357. hjt@opal.warwick.ac.uk (1988-)      \/      reality if reality were a dream.
  358. ______________________________________________________________________________
  359.